﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.SM
{
    class Class22
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            int ffee = 0;
            int basicfee = 0;
            int extrafee = 0;
            int addfee = 0;

            double deduct = 0;

            int overPeriod = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("约定缴费期(年)"));

            double wp = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("稳健型子账户比例");
            double wf = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("稳健型账户分红率(预估)");

            if (ppa.Period < overPeriod)
            {
                ffee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("期交保险费"));

                basicfee = ffee > 6000 ? 6000 : ffee;
                extrafee = ffee - basicfee;

                if (ppa.Period == 0)
                {
                    deduct = basicfee * 0.2;
                    deduct += extrafee * 0.05;
                }
                else if (ppa.Period == 1)
                {
                    deduct = basicfee * 0.1;
                    deduct += extrafee * 0.05;
                }
                else 
                {
                    deduct = basicfee * 0.05;
                    deduct += extrafee * 0.05;
                }
             
            }

            if (ppa.SchemePeriodActing.InsurantStates.Contains("追加费用"))
            {
                addfee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("追加费用"));
                deduct += addfee * wp * 0.05;
            }

            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                if (ppa.Period > 0 && ppa.PolicyActing.Policy.Fees[ppa.Period] <= double.Epsilon)
                {
                    ppa.PolicyActing.Policy.Fees[ppa.Period] = ppa.PolicyActing.Policy.Fees[ppa.Period - 1];
                }


                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];
                deduct += d;//约定风险金对应的保费

            }


            da.Value = ffee * wp + addfee - deduct ;

            if (ppa.Period > 2 && ppa.Period < overPeriod)
            {
                da.Value += ffee * wp * 0.02;
            }

            if (ppa.Period > 0)
            {
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];
                da.Value += pppa.GetDutyTotalValue("稳健型个人账户") * wf;
            }

            ppa.Fee = ffee + addfee;
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            int ffee = 0;
            int basicfee = 0;
            int extrafee = 0;
            int addfee = 0;

            double deduct = 0;

            int overPeriod = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("约定缴费期(年)"));

            double jp =1- (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("稳健型子账户比例") ;
            double jf = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("进取型账户分红率(预估)");

            if (ppa.Period < overPeriod)
            {
                ffee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("期交保险费"));

                basicfee = ffee > 6000 ? 6000 : ffee;
                extrafee = ffee - basicfee;

                if (ppa.Period == 0)
                {
                    deduct = basicfee * 0.2;
                    deduct += extrafee * 0.05;
                }
                else if (ppa.Period == 1)
                {
                    deduct = basicfee * 0.1;
                    deduct += extrafee * 0.05;
                }
                else
                {
                    deduct = basicfee * 0.05;
                    deduct += extrafee * 0.05;
                }

            }

            if (ppa.SchemePeriodActing.InsurantStates.Contains("追加费用"))
            {
                addfee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("追加费用"));
                deduct += addfee * 0.05;
            }

            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                if (ppa.Period > 0 && ppa.PolicyActing.Policy.Fees[ppa.Period] <= double.Epsilon)
                {
                    ppa.PolicyActing.Policy.Fees[ppa.Period] = ppa.PolicyActing.Policy.Fees[ppa.Period - 1];
                }


                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];
                deduct += d;//约定风险金对应的保费

            }


            da.Value = (ffee + addfee - deduct) * jp;

            if (ppa.Period > 2 && ppa.Period < overPeriod)
            {
                da.Value += ffee * jp * 0.02;
            }

            if (ppa.Period > 0)
            {
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];
                da.Value += pppa.GetDutyTotalValue("进取型个人账户") * jf;
            }

            ppa.Fee = ffee + addfee;
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                if (ppa.Period > 0 && ppa.PolicyActing.Policy.Fees[ppa.Period] <= double.Epsilon)
                {
                    ppa.PolicyActing.Policy.Fees[ppa.Period] = ppa.PolicyActing.Policy.Fees[ppa.Period - 1];
                }

                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];

                da.Value = d;
            }
        }

    }
}
